package atomic.atomicmarkeablerefrence;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicMarkableReference;

/**
 * @author ZhuQi
 * @ClassName Demo
 * @Date 2022/9/16 11:07
 * @Version 1.0
 * @Description 测试 AtomicMarkableReference
 */
@Slf4j
public class Demo {

    public static void main(String[] args) {
        AtomicMarkableReference<Integer> markableReference = new AtomicMarkableReference<>(0, false);

        // 获取结果 和修改标识
        Integer reference = markableReference.getReference();
        boolean marked = markableReference.isMarked();
        log.info("reference:{}  marked:{}", reference, marked);

        // 获取结果 和修改标识
        boolean b = markableReference.compareAndSet(0, 1, false, true);
        boolean marked1 = markableReference.isMarked();
        Integer reference1 = markableReference.getReference();
        log.info("reference:{}  b:{} marked1:{}", reference1, b, marked1);
    }
}
